package com.webtest.tag;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/8/12 15:32
 */
public class MaxTag extends SimpleTagSupport {

    private static final Logger LOGGER = LoggerFactory.getLogger(MaxTag.class);
    private String value1;
    private String value2;

    public void setValue1(String value1) {
        this.value1 = value1;
    }

    public void setValue2(String value2) {
        this.value2 = value2;
    }

    @Override
    public void doTag() throws JspException, IOException {
        int v1 = 0;
        int v2 = 0;
        try {
            v1 = Integer.parseInt(value1);
            v2 = Integer.parseInt(value2);
        } catch (Exception e) {
            LOGGER.error("convert error", e);
            return;
        }
        String msg = "";
        if (v1 >= v2) {
            msg= "value1-" + value1 + " is greater than value2-" + value2;
        } else {
            msg = "value1-" + value1 + " is less than value2-" + value2;
        }
        JspWriter writer = getJspContext().getOut();
        writer.print(msg);
        writer.print("<br/>");
    }
}
